//
//  GroupGongGaoTableViewCell.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/4/9.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "GroupGongGaoTableViewCell.h"

@interface GroupGongGaoTableViewCell ()

@property (nonatomic, strong) UIView *whiteBackGroundView;

@end

@implementation GroupGongGaoTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.05];
        [self addMySubview];
    }
    return self;
}

// 布局
- (void)addMySubview
{
    // 白色背景
    self.whiteBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(20 * kAdjustParamater , 0, 335 * kAdjustParamater, self.height)];
    self.whiteBackGroundView.backgroundColor = [UIColor whiteColor];
    self.whiteBackGroundView.layer.cornerRadius = 10 * kAdjustParamater;
    [self.contentView addSubview:_whiteBackGroundView];
    
    self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, 15 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
 //   self.timeLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.timeLabel.textAlignment = NSTextAlignmentLeft;
    self.timeLabel.textColor = [UIColor blackColor];
    self.timeLabel.font = [UIFont systemFontOfSize:k18Big];
    [self.whiteBackGroundView addSubview:_timeLabel];
    
    // 发送者姓名
    self.senderNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, self.timeLabel.bottom + 8 * kAdjustParamater, 200 * kAdjustParamater, 15 * kAdjustParamater)];
   // self.senderNameLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.senderNameLabel.textAlignment = NSTextAlignmentLeft;
    self.senderNameLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    self.senderNameLabel.font = [UIFont systemFontOfSize:k15Big];
    [self.whiteBackGroundView addSubview:_senderNameLabel];
    
    // 公告标题
    self.gongGaoTitle = [[UILabel alloc] initWithFrame:CGRectMake(self.senderNameLabel.left, self.senderNameLabel.bottom + 8 * kAdjustParamater, 300 * kAdjustParamater, 15 * kAdjustParamater)];
   // self.gongGaoTitle.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.gongGaoTitle.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
    self.gongGaoTitle.font = [UIFont systemFontOfSize:k15Big];
    [self.whiteBackGroundView addSubview:_gongGaoTitle];
    
    // 灰色横线
    UILabel *lineGrayOnSenderNameBottom = [[UILabel alloc] initWithFrame:CGRectMake(0, self.gongGaoTitle.bottom + 8 * kAdjustParamater, self.whiteBackGroundView.width, 1 * kAdjustParamater)];
    lineGrayOnSenderNameBottom.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    [self.whiteBackGroundView addSubview:lineGrayOnSenderNameBottom];
    
    // 内容
    self.myContentLabel = [[UILabel alloc] initWithFrame:CGRectMake(15 * kAdjustParamater, lineGrayOnSenderNameBottom.bottom + 8 * kAdjustParamater, self.whiteBackGroundView.width - 30 * kAdjustParamater, 50 * kAdjustParamater)];
  //  self.myContentLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
    self.myContentLabel.numberOfLines = 0;
    self.myContentLabel.textAlignment = NSTextAlignmentLeft;
    self.myContentLabel.textColor = [[UIColor blackColor] colorWithAlphaComponent:0.9];
    self.myContentLabel.font = [UIFont systemFontOfSize:k15Big];
    [self.whiteBackGroundView addSubview:_myContentLabel];
    
    
    
}

- (void)setModel:(GroupGongGaoModel *)model
{
    self.timeLabel.text = [NSString stringWithFormat:@"%@公告", model.time];
    self.senderNameLabel.text = model.senderName;
    self.gongGaoTitle.text = model.gongGaoTitle;
    NSLog(@"公告:%@", model.gongGaoTitle);
    self.myContentLabel.text = model.content;
    // 自定义高度
    CGRect newFrame = self.myContentLabel.frame;
    newFrame.size.height = [[NetStatusHandle shareHandle] adjustHeight:self.myContentLabel.text size:15 width:305];
    self.myContentLabel.frame = newFrame;
    
    self.whiteBackGroundView.height = self.myContentLabel.bottom + 20 * kAdjustParamater;
    NSLog(@"self.whiteBackGroundView.height = %f", self.whiteBackGroundView.height);
    self.height = self.whiteBackGroundView.height;
    NSLog(@"self.height = %f", self.height);
}


@end
